public class project {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int row=obstacleGrid.length;
        int col=obstacleGrid[0].length;
        int[] f=new int[col];
        f[0]=obstacleGrid[0][0]==1?0:1;
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                if(obstacleGrid[i][j]==1){
                    f[j]=0;
                    continue;
                }
                if(j-1>=0&&obstacleGrid[i][j-1]==0){
                    f[j]+=f[j-1];
                }
            }
        }
        return f[col-1];
    }













    public boolean searchMatrix(int[][] matrix, int target) {
        int cur=0;
        int row=matrix.length;
        int col=matrix[0].length;
        int i=0;
        int j=col-1;
        while (i<row&&i>=0&&j>=0&&j<col){
            cur=matrix[i][j];
            if(cur>target){
                j--;
            }else if(cur<target){
                i++;
            }else{
                return true;
            }
        }
        return false;
    }








    public int countQuadruplets(int[] nums) {
        int count=0;
        for(int i=0;i<nums.length-3;i++){
            for(int j=i+1;j<nums.length-2;j++){
                for(int k=j+1;k<nums.length-1;k++){
                    for(int p=k+1;p<nums.length;p++){
                        if((nums[i]+nums[j]+nums[k])==nums[p]){
                            count++;
                        }
                    }
                }
            }
        }
        return count;
    }
}
